<?php defined('_JEXEC') or die('Restricted access'); 

//$ordering = ($this->lists['order'] == 'ordering');
//$Itemid = JRequest::getVar( 'Itemid', 0, 'get', 'int' );
JHTML::_('behavior.tooltip');
JHTML::stylesheet('base.css', JURI::root().'components/com_simplelisting/css/');
JHTML::stylesheet('listing.css', JURI::root().'/components/com_simplelisting/css/themes/'.$this->select_theme.'/');
$token =JUtility::getToken();
?>
<script language="javascript" type="text/javascript">	
</script>
<div id="listing_details"><!-- Start main container div-->
    <div id="listing_details_inner"><!-- Start inner div -->
        <form action="" method="post" name="adminForm" >
            <div class="header">
               <table class="general_details">
                   <tbody>
                       <tr>
                           <td class="cw_title_main">
                                <?php echo JText::_('FT_MANAGER')?>
                           </td>
                       </tr>
                   </tbody>
               </table>
            </div>
<?php
    $user =& JFactory::getUser();
    if ($user->guest) { ?>
         <div style="width:100%; height:10px;"></div>
        <input type="button" onClick="javascript:window.location='<?php echo JRoute::_( 'index.php?option=com_user&view=login'); ?>'" value="<?php echo JText::_('BT_LOGIN'); ?>" class="button" >
         <div style="width:100%; height:10px;"></div>
        <?php
    } elseif ($user->usertype == "Super Administrator" || $user->usertype == "Administrator" || $user->usertype == "Manager" || $user->usertype == "Registered" ){
    ?>
    <span id="cw_back_button_top">
       <input type="button" onClick="javascript:window.location='<?php echo JRoute::_( 'index.php?option='.JRequest::getVar('option').'&task=add'); ?>'" value="<?php echo JText::_('BT_ADD_LISTING'); ?>" class="button" >
    </span>
   <?php
    }?>
 <?php
    $user =& JFactory::getUser();
    if (!$user->guest) { ?>
<div style="width:100%; height:10px;"></div>
    <table class="cw_listing">
	<thead>
            <tr>
                <th width="6%" colspan=2><?php echo JTEXT::_('LABEL_EDIT'); ?> </th>
                <th width="4%"><?php echo JTEXT::_('LABEL_ID'); ?></th>
                <th width="25%"><?php echo JText::_('LABEL_NAME')?></th>
                <th width="10%"><?php echo JText::_('LABEL_TYPE')?></th>
                <th width="15%"><?php echo JText::_('LABEL_CATEGORY')?></th>
                <th width="10%"><?php echo JText::_('LABEL_CONTACT_NAME')?></th>
                <th width="8%"><?php echo JText::_('LABEL_PUBLISHED')?></th>
                <th width="10%"><?php echo JText::_('LABEL_POSTED_DATE')?></th>
            </tr>
	</thead>	
    <tbody>
	<?php
    $user =& JFactory::getUser();

    if($user->usertype == "Super Administrator" || $user->usertype == "Administrator" || $user->usertype == "Manager" ){
        $k = 0;
        for ($i=0, $n=count( $this->items ); $i < $n; $i++)
        {
		$row = &$this->items[$i];
                $link = JRoute::_( 'index.php?option='.JRequest::getVar('option').'&task=edit&cid[]='. $row->id );
                $link1 = JRoute::_( 'index.php?option='.JRequest::getVar('option').'&task=remove&cid[]='. $row->id );
		$published  = JHTML::_('grid.published', $row, $i );
		?>
	<tr class="<?php echo "row$k"; ?>">
            <td>
            <a href="<?php echo JRoute::_( $link ) ?>" title="<?php echo JText::_('TT_EDIT_LISTING') ?>"><?php echo JHTML::_('image.site', 'edit.png', '/components/com_simplelisting/images/') ?></a>
            </td>
            <td>
            <a href="<?php echo JRoute::_( $link1 ) ?>" title="<?php echo JText::_('TT_DELETE_LISTING') ?>"onclick="return confirm('<?php echo JText::_('Are you sure you want to delete this item?') ?>')"><?php echo JHTML::_('image.site', 'delete.png', '/components/com_simplelisting/images/') ?></a>
            </td>
	    <td><?php echo $this->pagination->getRowOffset( $i ); ?></td>
            <td><?php echo $row->name; ?></td>
            <td><?php echo $this->escape( $row->type ); ?></td>
            <td><?php echo $this->escape( $row->category); ?></td>
            <td><?php echo $this->escape( $row->username); ?></td>
            <td><?php echo $row->published ? JHTML::_('image.site', 'accept.png', '/components/com_simplelisting/images/') : JHTML::_('image.site', 'delete.png', '/components/com_simplelisting/images/') ?></td>
            <td><?php echo JHTML::_('date',  $row->date_created, JText::_('DATE_FORMAT_LC4') ); ?></td>
	</tr>
		<?php
         $k = 1 - $k;
         
        }
    }
    elseif($user->usertype =="Registered")
    { 
        $k = 0;
        for ($i=0, $n=count( $this->items ); $i < $n; $i++)
        {
	$row = &$this->items[$i];
        $link = JRoute::_( 'index.php?option='.JRequest::getVar('option').'&task=edit&cid[]='. $row->id );  
        $link1 = JRoute::_( 'index.php?option='.JRequest::getVar('option').'&task=remove&cid[]='. $row->id );
	$published  = JHTML::_('grid.published', $row, $i );
        if($user->id == $this->escape( $row->userid )){
		?>
	<tr class="<?php echo "row$k"; ?>">
           <td>
                <a href="<?php echo JRoute::_( $link ) ?>" title="<?php echo JText::_('Edit') ?>"><?php echo JHTML::_('image.site', 'edit.png', '/components/com_simplelisting/images/') ?></a>
           </td>
           <td>
                <a href="<?php echo JRoute::_( $link1 ) ?>" title="<?php echo JText::_('Delete') ?>"onclick="return confirm('<?php echo JText::_('Are you sure you want to delete this item?') ?>')"><?php echo JHTML::_('image.site', 'delete.png', '/components/com_simplelisting/images/') ?></a>
           </td>
            <td><?php echo $this->pagination->getRowOffset( $i ); ?></td>
            <td><?php echo $row->name; ?></td>
            <td><?php echo $this->escape( $row->type ); ?></td>
            <td><?php echo $this->escape( $row->category); ?></td>
            <td><?php echo $this->escape( $row->username); ?></td>
            <td><?php echo $row->published ? JHTML::_('image.site', 'accept.png', '/components/com_simplelisting/images/') : JHTML::_('image.site', 'delete.png', '/components/com_simplelisting/images/') ?></td>
			<td><?php echo JHTML::_('date',  $row->date_created, JText::_('DATE_FORMAT_LC4') ); ?></td>
		</tr>
		<?php
         $k = 1 - $k;
            }
            
        }
        
    }
    ?>
    </tbody>
    </table>
            <input type="hidden" name="option" value="com_simplelisting"/>
            <input type="hidden" name="task" value="display" />
            <input type="hidden" name="boxchecked" value="0" />
            <input type="hidden" name="view" value="manage" />
            
<?php if($user->usertype == "Super Administrator" || $user->usertype == "Administrator" || $user->usertype == "Manager" ){ ?>
                <div id="sl-pagnation">
                    <table class="pagnation" width="100%" border="0">
                       <tbody>
                           <tr>
                               <td>
                                <?php  echo $this->pagination->getListFooter(); ?>
                               </td>
                           </tr>
                        </tbody>
                    </table>
                </div>
<?php } ?>
<?php } ?>
            <?php if ( $this->params->get( 'show_poweredby' ) ) : ?>
                <div class="cw_powerbyfront">
                    <span class="cw_powerbyfront"><?php echo JTEXT::_('POWEREDBY_MSG'); ?> <a href="http://www.celtaweb.com" target="_blank" title="CeltaWeb">CeltaWeb</a> </span>
                </div>
            <?php endif ?>
        </form><!-- End listing form -->
    </div><!-- End inner div -->
</div><!-- End main container div -->
